package com.gxa.jjty.admin.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.gxa.jjty.admin.service.VSRoyaltyService;
import com.gxa.jjty.core.pojo.VSRoyalty;
import com.gxa.jjty.core.service.impl.BaseServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.common.Mapper;
import tk.mybatis.mapper.entity.Example;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Service
@Transactional(rollbackFor = Throwable.class)
public class VSRoyaltyServiceImpl extends BaseServiceImpl<VSRoyalty> implements VSRoyaltyService {

    @Autowired
    Mapper<VSRoyalty> vsRoyaltyMapper;

    @Override
    public PageInfo<VSRoyalty> selectRoyalty(Integer page, Integer size, String startTime, String endTime, String phyName, Integer royaltyStatus) {
       /* SimpleDateFormat formatter= new SimpleDateFormat("yyyy-MM-dd ");
        String sTime = formatter.format(startTime);
        String eTime = formatter.format(endTime);*/
        page = (page-1)*size;
        PageHelper.startPage(page,size);
        Example example = new Example(VSRoyalty.class);
        Example.Criteria criteria = example.createCriteria();
        if (phyName != null && phyName !=""){
            criteria.andLike("name","%"+phyName+"%");
        }
        if (startTime != null && startTime!="" && endTime != null && endTime !=""){

            criteria.andBetween("date",startTime,endTime);
        }
        if (royaltyStatus != null){
            criteria.andEqualTo("royaltyStatus",royaltyStatus);
        }
        example.orderBy("date").desc();
        List<VSRoyalty> vsRoyalties = vsRoyaltyMapper.selectByExample(example);
        PageInfo<VSRoyalty> vsRoyaltyPageInfo = PageInfo.of(vsRoyalties);

        System.out.println(vsRoyaltyPageInfo.getList());
        return vsRoyaltyPageInfo;
    }
}
